package com.yuerlive.rainbow.module.playlive.presenter;

import com.yuerlive.rainbow.api.LiveApi;
import com.yuerlive.rainbow.api.LiveService;
import com.yuerlive.rainbow.base.BasePresenter;
import com.yuerlive.rainbow.base.BasePresenterImpl;
import com.yuerlive.rainbow.entity.BaseData;
import com.yuerlive.rainbow.entity.CloseData;
import com.yuerlive.rainbow.entity.User;
import com.yuerlive.rainbow.module.main.presenter.MainContract;
import com.yuerlive.rainbow.rx.RxHelper;
import com.yuerlive.rainbow.rx.RxObserver;
import com.yuerlive.rainbow.utils.UserProxy;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by xiaoyi on 2017/6/12.
 */

public class LiveEndPresenter extends BasePresenterImpl implements LiveEndContract.Presenter {
    LiveService liveService;
    LiveEndContract.View view;

    public LiveEndPresenter(LiveEndContract.View view) {
        this.view = view;
        this.view.setPresenter(this);
        liveService = LiveApi.getInstance().liveService;
    }

    @Override
    public void closeLive() {
        view.showLoading();
        Map<String, String> params = new HashMap<>();
        User user = UserProxy.getUser();

        liveService.closeLive(params).compose(RxHelper.toUI())
                .subscribe(new RxObserver<BaseData<CloseData>>(this) {
                    @Override
                    protected void onSuccess(BaseData<CloseData> closeData) {
                        view.hideLoading();
                        view.showCloseInfo(closeData.getObject());
                    }

                    @Override
                    protected void onFail(String message) {

                    }
                });
    }
}
